package com.xy.demo.Test;


import com.sun.org.apache.bcel.internal.generic.SWITCH;
import com.xy.demo.Util.Util;

import java.io.Console;
import java.util.Scanner;

/**
 * 设计模式测试
 */
public class FactoryTest {
    public static void main(String[] args) {
        System.out.println("please system in oneNumber");
        Scanner reader = new Scanner(System.in);
        String aNumber = reader.next();
        System.out.println("please system in option ");
        Scanner reader1 = new Scanner(System.in);
        String operation = reader1.next();
        System.out.println("please system in otherNumber");
        Scanner reader2 = new Scanner(System.in);
        String bNumber = reader2.next();
        String result = calResult(Double.valueOf(aNumber),Double.valueOf(bNumber),operation);
        System.out.println("result is :"+result);
    }

    /**
     * 面向对象之封装  /继承/多态
     * @param num1
     * @param num2
     * @param Operation
     * @return
     */
    public static String calResult(Double num1,Double num2,String Operation){
        String result = "";
        switch (Operation){
            case "+":
                result = Util.toString(num1+num2);
                break;
            case "-":
                result = Util.toString(num1-num2);
                break;
            case "*":
                result = Util.toString(num1*num2);
                break;
            case "/":
                if(num2==0){
                    result = "params is mistake";
                }else{
                    result = Util.toString(num1/num2);
                }
                break;
        }
        return result;
    }

}
